<?php
/**
 * Created by PhpStorm.
 * User: ybjaa
 * Date: 2017/7/12
 * Time: 11:05
 */

namespace App\Extend;


use Illuminate\Support\Facades\Auth;

trait UserIDInfo
{
    public function GetUserID()
    {
        $ID=request()->session()->get("ID");
        return $ID?$ID+0:null;

    }


    public function Check()
    {
        $ID=request()->session()->get("ID");
        return $ID==null?false:true;

    }


    public function ClearUser()
    {
        request()->session()->remove("ID");
        Auth::logout();
        request()->session()->flush();

    }

    public function setUserID($ID)
    {
        request()->session()->put("ID",$ID);
    }

    public function SetUserIDFromUser()
    {
        $user=Auth::user();

        if($user&&$user->ID)
        {
            request()->session()->put("ID",$user->ID);
        }
    }
}